package com.songdehuai.imageselect.picture;

import android.app.Activity;
import android.content.Intent;

import com.luck.picture.lib.entity.LocalMedia;

import java.util.List;

/**
 * 描述：简易观察者模式回调图片
 *
 * @author songdehuai
 * @ClassName: com.songdehuai.imageselect.picture.
 * @date 2018/6/8 11:00
 */
public class MyPictureSelector {

    private static MyPictureSelector notificationCenter = null;

    private PictureSelectorCallBack pictureSelectorCallBack;

    private MyPictureSelector() {
    }

    public static MyPictureSelector getInstance() {
        if (notificationCenter == null) {
            notificationCenter = new MyPictureSelector();
        }
        return notificationCenter;
    }

    public MyPictureSelector setCallBack(PictureSelectorCallBack pictureSelectorCallBack) {
        this.pictureSelectorCallBack = pictureSelectorCallBack;
        return this;
    }

    public MyPictureSelector startPictureSelector(Activity activity, int MAX_COUNT, boolean isCamera) {
        Intent intent = new Intent(activity, PictureSelectorActivity.class);
        intent.putExtra("MAX_COUNT", MAX_COUNT);
        intent.putExtra("ISCAMERA", isCamera);
        activity.startActivity(intent);
        activity.overridePendingTransition(0, 0);
        return this;
    }


    public void postNotification(List<LocalMedia> localMedia) {
        if (pictureSelectorCallBack != null) {
            pictureSelectorCallBack.onSuccess(localMedia);
        }
    }


}
